// 导入express
const express = require('express')
// 创建路由对象
const router = express.Router()

// 导入文章的路由处理函数模块
const article_handler = require('../router_handler/article.js')

// 表单数据校验规则
const expressJOI = require('@escook/express-joi')
const { add_article_schema, list_article_schema, detail_article_schema, del_article_schema } = require('../schema/article.js')

// 导入解析formdata格式表单数据的包
const multer = require('multer')
// 导入处理路径的核心模块
const path = require('path')

// 创建multer的实例对象，通过dest属性指定文件的存放路径
const upload = multer({ dest: path.join(__dirname, '../uploads') })

// 发布新文章
router.post('/add', upload.single('cover_img'), expressJOI(add_article_schema), article_handler.addArticle)
// 获取文章列表
router.get('/list', expressJOI(list_article_schema), article_handler.listArticle)
// 获取文章详情
router.get('/info', expressJOI(detail_article_schema), article_handler.queryArticleDetail)
// 根据id删除文章
router.delete('/info', expressJOI(del_article_schema), article_handler.delArticleDetail)

// 向外共享路由对象
module.exports = router